import PAGE from '../../../utils/middleware/page'
import { storeBindingsBehavior } from 'mobx-miniprogram-bindings'
import store from '../../../store/index'
const app = getApp()
Page(PAGE({
    data: {
        loading: false,
        loaded: false,
        list: [],
        listField: {
            module: 'charge',
            api: 'PageQuery'
        },
        searchParams: {
            PageIndex: 1,
            PageSize: 15,
            Status: null
        },

    },
    onLoad(options) {
        if (options[0]) {
            this.data.searchParams.Status = options[0]
        }
        this.init()
    },
    onPullDownRefresh() {
        this.setData({ list: [] });
        this.init();
        wx.stopPullDownRefresh();
    },
    onReachBottom() {
        if (this.data.loaded) return;
        this.fetchList();
    },
    init() {
        this.data.searchParams.PageIndex = 1;
        this.fetchList();

    },
    async fetchList() {
        this.handleFetchListData({}, 'listField', this.data.searchParams.PageIndex == 1)
    },
    async handleStop(e) {
        var id = e.currentTarget.dataset.id
        var _this = this
        wx.showModal({
            title: '提示',
            content: '确定要结束充电吗？',
            success: async function (showRes) {
                if (showRes.confirm) {
                    _this.doStop(id)
                }
            }
        })
    },
    async doStop(id) {

        try {
            const res = await wx.$Api.charge.Cancel({ data: { id: id } })
            this.init()
            wx.$Fun.showToast("成功结束充电")
        }
        catch (e) {
            wx.$Fun.showToast(e.Message)
        }
    }
}))